<?
/***********************************************************************/
/*                                                                     */
/*  This file is created by deZender                                   */
/*                                                                     */
/*  deZender (Decoder for Zend Encoder/SafeGuard):                     */
/*    Version:      0.9.3.0                                            */
/*    Author:       qinvent.com                                        */
/*    Release on:   2005.11.12                                         */
/*                                                                     */
/***********************************************************************/


  function main ()
  {
    global $frm_env;
    if (!is_writeable ('settings.php'))
    {
      print '<br><br><br><br><center><h1>Please set 666 permissions for <b>settings.php</b> file!<br>';
      exit ();
    }

    if (!is_dir ('tmpl_c'))
    {
      print '<br><br><br><br><center><h1>Please create directory <b>tmpl_c</b> with 777 permissions!<br>';
      exit ();
    }

    $file = @fopen ('tmpl_c/test', 'w');
    if (!$file)
    {
      print '<br><br><br><br><center><h1>Please set 777 permissions for <b>tmpl_c</b> folder!<br>';
      exit ();
    }

    require 'inc/libs/Smarty.class.php';
    $smarty = new Smarty ();
    $smarty->compile_check = true;
    $smarty->template_dir = './tmpl/';
    $smarty->compile_dir = './tmpl_c';
    $smarty->assign ('hostname', $frm_env['HTTP_HOST']);
    $smarty->assign ('install', 1);
    $smarty->display ('install.tpl');
    exit ();
  }

  ini_set ('error_reporting', 'E_ALL & ~E_NOTICE');
  include 'inc/config.inc.php';
  if ($frm['a'] == 'install')
  {
    $ok = 1;
    require 'inc/libs/Smarty.class.php';
    $smarty = new Smarty ();
    $smarty->compile_check = true;
    $smarty->template_dir = './tmpl/';
    $smarty->compile_dir = './tmpl_c';
    $smarty->assign ('form_data', $frm);
    $settings['license'] = $frm['license_string'];
    $str = send_string_to_gold_coders_install ();
    $dbconn = @mysql_connect ($frm['mysql_host'], $frm['mysql_username'], $frm['mysql_password']);
    $c = @mysql_select_db ($frm['mysql_db']);
    if (!$c)
    {
      $smarty->assign ('wrong_mysql_data', 1);
      $ok = 0;
    }

    if ($ok == 1)
    {
      $q = '
CREATE TABLE `hl_ads` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `ordering` int(10) unsigned NOT NULL default \'0\',
  `title` varchar(255) default NULL,
  `text` varchar(255) default NULL,
  `date` date default NULL,
  `expiration` int(10) unsigned default \'0\',
  `url` text,
  PRIMARY KEY  (`id`)
)';
      mysql_query ($q);

      $q = '
CREATE TABLE `hl_bookmarks` (
  `user_id` bigint(20) NOT NULL,
  `listing_id` bigint(20) NOT NULL,
  PRIMARY KEY  (`user_id`,`listing_id`)
)';
      mysql_query ($q);

      $q = '
CREATE TABLE `hl_users` (
  `user_id` bigint(20) NOT NULL auto_increment,
  `username` varchar(50) character set cp1251 NOT NULL,
  `email` varchar(255) character set cp1251 NOT NULL,
  `password` varchar(34) NOT NULL,
  `last_access_time` datetime default NULL,
  `last_access_ip` varchar(20) character set latin1 default NULL,
  PRIMARY KEY  (`user_id`)
)';
      mysql_query ($q);

      $q = '
CREATE TABLE `hl_emails` (
  `id` varchar(50) NOT NULL default \'\',
  `name` varchar(255) NOT NULL default \'\',
  `subject` varchar(255) NOT NULL default \'\',
  `text` text,
  UNIQUE KEY `id` (`id`)
)';
      mysql_query ($q);
      $q = 'INSERT INTO hl_emails VALUES("vote_confirm", "Vote Confirmation", "#site_name# - Vote Confirmation", "Hello.\\n\\nYou have place vote for #listing_name#.\\n\\nTo confirm it please follow this link:\\n#site_url#?a=add_vote&action=confirm&code=#confirm_code#\\n\\nThank you.\\n#site_name#")';
      mysql_query ($q);
      $q = 'INSERT INTO hl_emails VALUES("listing_confirm", "Listing Confirmation", "#site_name# - Listing Confirmation", "Hello.\\n\\nYou have place listing #listing_name#.\\n\\nTo confirm it please follow this link:\\n#site_url#?a=add&action=confirm&code=#confirm_code#\\n\\nThank you.\\n#site_name#")';
      mysql_query ($q);
      $q = 'INSERT INTO hl_emails VALUES("listing_added", "Admin Addition Notification", "#site_name# - New Listing has been added", "New Listing has been added to #site_name#:\\nGroup: #group#\\nDate: #date_added#\\nName: #name#\\nURL : #url#\\nEmail: #email#\\nInterest Percents: #percents#\\nMinimum Spend: #min_spend#\\nMaximum Spend: #max_spend#\\nReferral Bonus: #referral#\\nWithdrawal Type: #withdrawal_type#\\nSupport Email: #support_email#\\nTG Support Forum: #support_form#\\nMMG Support Forum: #support_forum#\\nDTM Support Forum: #support_aim#\\nPayment Methods: #pay_systems#\\nDescription:\\n#description#")';
      mysql_query ($q);
      $q = 'INSERT INTO hl_emails VALUES("listing_approve", "Listing Approval Notification", "#site_name# - Your listing has been approved", "Your Listing has been approved!\\n\\nYou should use this link to our site:\\n#site_url#?a=details&lid=#id#\\n\\nListing Details:\\nGroup: #group#\\nDate: #date_added#\\nName: #name#\\nURL : #url#\\nEmail: #email#\\nInterest Percents: #percents#\\nMinimum Spend: #min_spend#\\nMaximum Spend: #max_spend#\\nReferral Bonus: #referral#\\nWithdrawal Type: #withdrawal_type#\\nSupport Email: #support_email#\\nMMG Support Forum: #support_form#\\nTG Support Forum: #support_forum#\\nMMG Support Forum: #support_aim#\\nPayment Methods: #pay_systems#\\nDescription:\\n#description#\\n\\nThank you.")';
      mysql_query ($q);
      $q = 'INSERT INTO hl_emails VALUES("listing_decline", "Listing Decline Notification", "#site_name# - Your listing has been declined", "Your Listing has been declined!\\n\\nListing Details:\\nGroup: #group#\\nDate: #date_added#\\nName: #name#\\nURL : #url#\\nEmail: #email#\\nInterest Percents: #percents#\\nMinimum Spend: #min_spend#\\nMaximum Spend: #max_spend#\\nReferral Bonus: #referral#\\nWithdrawal Type: #withdrawal_type#\\nSupport Email: #support_email#\\nTG Support Forum: #support_form#\\nMMG Support Forum: #support_forum#\\nDTM Support Forum: #support_aim#\\nPayment Methods: #pay_systems#\\nDescription:\\n#description#\\n\\nThank you.")';
      mysql_query ($q);
      $q = '
CREATE TABLE `hl_groups` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `name` varchar(255) default NULL,
  `nav_name` varchar(255) default NULL,
  `type` varchar(255) default NULL,
  `add_description` text,
  `sort` varchar(255) default NULL,
  `status` tinyint(1) unsigned NOT NULL default \'1\',
  `reg_enabled` tinyint(1) unsigned NOT NULL default \'0\',
  `onindex` tinyint(1) unsigned NOT NULL default \'1\',
  `onnew` tinyint(1) unsigned default \'0\',
  `expiration` int(10) unsigned NOT NULL default \'0\',
  PRIMARY KEY  (`id`)
)';
      mysql_query ($q);
      $q = 'INSERT INTO hl_groups VALUES("1", "Premium", "Premium", "Premium", "", "pratio", "1", "1", "1", "1", "0")';
      mysql_query ($q);
      $q = 'INSERT INTO hl_groups VALUES("2", "Normal", "Normal", "Normal", "", "pratio", "1", "1", "1", "1", "0")';
      mysql_query ($q);
      $q = 'INSERT INTO hl_groups VALUES("3", "Trial", "Trial", "Trial", "", "pratio", "1", "1", "1", "1", "0")';
      mysql_query ($q);
      $q = 'INSERT INTO hl_groups VALUES("4", "Free", "Free", "Free", "", "traffic_in", "1", "1", "0", "0", "0")';
      mysql_query ($q);
      $q = 'INSERT INTO hl_groups VALUES("5", "Games", "Games", "Games", "", "rating", "1", "1", "1", "1", "0")';
      mysql_query ($q);
      $q = 'INSERT INTO hl_groups VALUES("6", "Scam", "Scam", "Scam", "", "adate", "1", "0", "1", "0", "0")';
      mysql_query ($q);
      $q = 'INSERT INTO hl_groups VALUES("7", "Closed", "Closed", "Closed", "1", "rating", "1", "0", "0", "0", "0")';
      mysql_query ($q);
      $q = '
CREATE TABLE `hl_in_log` (
  `ip` varchar(20) default NULL,
  `date` datetime default NULL,
  `listing_id` bigint(20) unsigned default NULL
)';
      mysql_query ($q);
      $q = '
CREATE TABLE `hl_listings` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `group_id` bigint(20) unsigned NOT NULL default \'0\',
  `name` varchar(255) default NULL,
  `url` text,
  `status` tinyint(1) NOT NULL default \'1\',
  `hyip_status` tinyint(1) unsigned NOT NULL default \'1\',
  `percents` varchar(255) default NULL,
  `min_spend` varchar(255) default NULL,
  `max_spend` varchar(255) default NULL,
  `referral` varchar(255) default NULL,
  `email` varchar(255) default NULL,
  `support_email` varchar(255) default NULL,
  `support_phone` varchar(255) default NULL,
  `support_form` text,
  `support_aim` varchar(255) default NULL,
  `support_forum` text,
  `date_added` datetime default NULL,
  `date_updated` datetime default NULL,
  `date_closed` date default NULL,
  `description` text,
  `pay_systems` varchar(255) default NULL,
  `withdrawal_type` tinyint(1) unsigned default \'1\',
  `rating` tinyint(1) unsigned default \'0\',
  `account` varchar(255) default NULL,
  `expiration` int(10) unsigned NOT NULL default \'0\',
  `confirm` varchar(255) NOT NULL default \'0\',
  PRIMARY KEY  (`id`)
)';
      mysql_query ($q);
      $q = '
CREATE TABLE `hl_maillist` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `email` varchar(255) default NULL,
  `ip` varchar(20) NOT NULL default \'\',
  PRIMARY KEY  (`id`)
)';
      mysql_query ($q);
      $q = '
CREATE TABLE `hl_news` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `date` datetime default NULL,
  `title` varchar(255) NOT NULL default \'\',
  `small_text` text,
  `full_text` text,
  `sponsored` tinyint(1) unsigned NOT NULL default \'0\',
  `expiration` int(10) unsigned NOT NULL default \'0\',
  PRIMARY KEY  (`id`)
) ';
      mysql_query ($q);
      $q = '
CREATE TABLE `hl_statistics` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `listing_id` bigint(20) unsigned default NULL,
  `type` tinyint(1) unsigned default \'0\',
  `date` datetime default NULL,
  `amount` double(10,2) default \'0.00\',
  `comment` varchar(255) default NULL,
  `batch` varchar(255) NOT NULL default \'\',
  PRIMARY KEY  (`id`)
)';
      mysql_query ($q);
      $q = '
CREATE TABLE `hl_traffic` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `date` date default NULL,
  `listing_id` bigint(20) unsigned NOT NULL default \'0\',
  `in` bigint(20) unsigned NOT NULL default \'0\',
  `out` bigint(20) unsigned NOT NULL default \'0\',
  PRIMARY KEY  (`id`)
)';
      mysql_query ($q);
      $q = '
CREATE TABLE `hl_votes` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `listing_id` bigint(20) unsigned default NULL,
  `vote` tinyint(1) unsigned default \'0\',
  `date` datetime default NULL,
  `comment` varchar(255) default NULL,
  `email` varchar(255) default NULL,
  `ip` varchar(20) default NULL,
  `confirm` varchar(255) NOT NULL default \'0\',
  PRIMARY KEY  (`id`)
)';
      mysql_query ($q);
      $q = '
CREATE TABLE `hl_languages` (
  `listing_id` bigint(20) unsigned NOT NULL default \'0\',
  `type` tinyint(3) unsigned NOT NULL default \'0\',
  `text` text,
  `ln` char(2) default NULL,
  KEY `listing_id` (`listing_id`,`type`,`ln`)
)';
      mysql_query ($q);
      $settings['site_name'] = $frm_env['HTTP_HOST'];
      $settings['site_url'] = 'http://' . $frm_env['HTTP_HOST'] . preg_replace ('/\\/install.php/', '', $frm_env['SCRIPT_NAME']);
      $settings['site_url_alt'] = 'http://' . $frm_env['HTTP_HOST'];
      $settings['hostname'] = $frm['mysql_host'];
      $settings['database'] = $frm['mysql_db'];
      $settings['db_login'] = $frm['mysql_username'];
      $settings['db_pass'] = $frm['mysql_password'];
      $settings['admin_email'] = $frm['admin_email'];
      $settings['system_email'] = $frm['system_email'];
      $settings['admin_login'] = $frm['admin_login'];
      $settings['admin_password'] = $frm['admin_password'];
      save_settings (); 
      $smarty->assign ('script_path', $settings['site_url']);
      $smarty->assign ('installed', 1);
    }
    mail ('goldencoders@gmail.com', 'Script Installed' . '-'. $frm_env['HTTP_HOST'],'');
    $smarty->assign ('hostname', $frm_env['HTTP_HOST']);
    $smarty->assign ('install', 1);
    $smarty->display ('install.tpl');
    exit ();
  }

  main ();
?>
